(function($){

	window.addEvent('domready', function(){
		var pages = $$('.page');
		var fx = new Fx.Elements(pages, {});

		var left = 0;
		pages.each(function(element, key){
			var width =  element.getWidth();
			var styles = {
				'position': 'absolute',
				'left': left
			};
			element.setStyles(styles);
			element.store('base', left);
			left = left + width;
		});

		var offsets = {};
		pages.addEvent('click', function(event){
			var si = pages.indexOf(this);
			var sp = pages[si];
			var spp = sp.retrieve('base');
			pages.each(function(page, key){
				var app = page.retrieve('base');
				var sl = page.getPosition().x;
				var el = (spp > app) ? -(spp - app) : (app - spp);
				offsets[key] = { left: [sl, el] };
			});

			fx.start(offsets);
		});
		var page = pages.getRandom();
		var event = document.createEvent('MouseEvents');
		event.initEvent('click', true, true);
		page.fireEvent.apply(page, ['click', event]);
	});

}(document.id));
